package com.china08.yxyapi.api.manage.stu.mystudy.huixue.exercise;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.mg.impl.PlanExerciseServiceImpl;

/**
 * 学生练习知识点下获取试题id
 *
 */
@RestController
public class PlanExerciseGetIdController extends YxyApiBaseController {

    @Autowired
    private PlanExerciseServiceImpl planExerciseServiceImpl;

    @RequestMapping(value = "/api_yw/manage/stu/mystudy/huixue/exercise/getid", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response) {

        Assert.notNull(StringUtils.defaultIfBlank(request.getParameter("pkid"), null), "学习计划知识点id不能为空");

        String questionId = planExerciseServiceImpl.exerciseRule(request.getParameter("pkid"));

        RespModel model = new RespModel();
        if (StringUtils.isNotBlank(questionId)) {
            model.questionId = questionId;
        }
        return model;
    }

    /**
     * 响应参数
     * 
     */
    protected static class RespModel extends YxyApiRespModel {
        // 试题id
        public String questionId;
    }
}
